package com.softer.chengxin.score.controller;

import com.softer.chengxin.common.domin.ManagerPageResult;
import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.score.entity.ScoreRecord;
import com.softer.chengxin.score.service.ScoreManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2018/10/12
 */
@RestController
public class ScoreManagerController {
    @Autowired
    private ScoreManagerService scoreManagerService;

    /**
     * 获取企业信用等级，总得分，优良信息得分，负面信息得分，基础信息得分
     *
     * @param session 缓存信息
     * @return 企业信用得分
     */
    @PostMapping(value = "/api/ScoreManager/GetScore")
    public ScoreRecord getScore(HttpSession session) {
        // 查询企业ID
        Integer id = (Integer) session.getAttribute("ID");
        if (id == null) {
            return new ScoreRecord();
        }
        return scoreManagerService.getScore(id);
    }

    /**
     * 获取企业信用等级列表
     *
     * @param page        页面实体
     * @param scoreRecord 查询实体
     * @param session     缓存
     * @return 信用等级集合
     */
    @PostMapping("/api/ScoreManager/getScoreList")
    public ManagerPageResult getScoreList(Page page, ScoreRecord scoreRecord, HttpSession session) {
        // 查询企业ID
        Integer id = (Integer) session.getAttribute("ID");
        if (id == null) {
            return new ManagerPageResult();
        }
        scoreRecord.setPoguid(id);
        return scoreManagerService.getScoreList(page, scoreRecord);
    }
}
